home *** CD-ROM | disk | FTP | other *** search
/ Isometric Game Programming with DirectX 7.0 / Isometric Game Programming.iso / source / chapter1 / isohex1_2 / isohex1_2.cpp next >
Encoding:
C/C++ Source or Header  |  2000-04-27  |  5.8 KB  |  227 lines

  1. /*****************************************************************************
  2. IsoHex1_2.cpp
  3. Ernest S. Pazera
  4. 27APR2000
  5. Start a WIN32 Application Workspace, add in this file
  6. No other libs are required
  7. *****************************************************************************/
  8.  
  9. //////////////////////////////////////////////////////////////////////////////
  10. //INCLUDES
  11. //////////////////////////////////////////////////////////////////////////////
  12. #define WIN32_LEAN_AND_MEAN  
  13.  
  14. #include <windows.h>   
  15.  
  16. //////////////////////////////////////////////////////////////////////////////
  17. //DEFINES
  18. //////////////////////////////////////////////////////////////////////////////
  19. //name for our window class
  20. #define WINDOWCLASS "ISOHEX1"
  21. //title of the application
  22. #define WINDOWTITLE "IsoHex 1-2"
  23.  
  24. //////////////////////////////////////////////////////////////////////////////
  25. //PROTOTYPES
  26. //////////////////////////////////////////////////////////////////////////////
  27. bool Prog_Init();//game data initalizer
  28. void Prog_Loop();//main game loop
  29. void Prog_Done();//game clean up
  30.  
  31. //////////////////////////////////////////////////////////////////////////////
  32. //GLOBALS
  33. //////////////////////////////////////////////////////////////////////////////
  34. HINSTANCE hInstMain=NULL;//main application handle
  35. HWND hWndMain=NULL;//handle to our main window
  36.  
  37. //////////////////////////////////////////////////////////////////////////////
  38. //WINDOWPROC
  39. //////////////////////////////////////////////////////////////////////////////
  40. LRESULT CALLBACK TheWindowProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
  41. {
  42.     //which message did we get?
  43.     switch(uMsg)
  44.     {
  45.     case WM_KEYDOWN:
  46.         {
  47.             //is this the Escape key?
  48.             if(wParam==VK_ESCAPE)
  49.             {
  50.                 //Destroy the main window
  51.                 //(this will have the cascading effect of closing the application)
  52.                 DestroyWindow(hWndMain);
  53.             }
  54.  
  55.         }break;
  56.     case WM_DESTROY://the window is being destroyed
  57.         {
  58.  
  59.             //tell the application we are quitting
  60.             PostQuitMessage(0);
  61.  
  62.             //handled message, so return 0
  63.             return(0);
  64.  
  65.         }break;
  66.     case WM_PAINT://the window needs repainting
  67.         {
  68.             //a variable needed for painting information
  69.             PAINTSTRUCT ps;
  70.             
  71.             //start painting
  72.             HDC hdc=BeginPaint(hwnd,&ps);
  73.  
  74.             /////////////////////////////
  75.             //painting code would go here
  76.             /////////////////////////////
  77.  
  78.             //end painting
  79.             EndPaint(hwnd,&ps);
  80.                         
  81.             //handled message, so return 0
  82.             return(0);
  83.         }break;
  84.     }
  85.  
  86.     //pass along any other message to default message handler
  87.     return(DefWindowProc(hwnd,uMsg,wParam,lParam));
  88. }
  89.  
  90.  
  91. //////////////////////////////////////////////////////////////////////////////
  92. //WINMAIN
  93. //////////////////////////////////////////////////////////////////////////////
  94. int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
  95. {
  96.     //assign instance to global variable
  97.     hInstMain=hInstance;
  98.  
  99.     //create window class
  100.     WNDCLASSEX wcx;
  101.  
  102.     //set the size of the structure
  103.     wcx.cbSize=sizeof(WNDCLASSEX);
  104.  
  105.     //class style
  106.     wcx.style=CS_OWNDC | CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  107.  
  108.     //window procedure
  109.     wcx.lpfnWndProc=TheWindowProc;
  110.  
  111.     //class extra
  112.     wcx.cbClsExtra=0;
  113.  
  114.     //window extra
  115.     wcx.cbWndExtra=0;
  116.  
  117.     //application handle
  118.     wcx.hInstance=hInstMain;
  119.  
  120.     //icon
  121.     wcx.hIcon=LoadIcon(NULL,IDI_APPLICATION);
  122.  
  123.     //cursor
  124.     wcx.hCursor=LoadCursor(NULL,IDC_ARROW);
  125.  
  126.     //background color
  127.     wcx.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
  128.  
  129.     //menu
  130.     wcx.lpszMenuName=NULL;
  131.  
  132.     //class name
  133.     wcx.lpszClassName=WINDOWCLASS;
  134.  
  135.     //small icon
  136.     wcx.hIconSm=NULL;
  137.  
  138.     //register the window class, return 0 if not successful
  139.     if(!RegisterClassEx(&wcx)) return(0);
  140.  
  141.     //create main window
  142.     hWndMain=CreateWindowEx(0,WINDOWCLASS,WINDOWTITLE, WS_BORDER | WS_SYSMENU | WS_VISIBLE,0,0,320,240,NULL,NULL,hInstMain,NULL);
  143.  
  144.     //error check
  145.     if(!hWndMain) return(0);
  146.  
  147.     //if program initialization failed, then return with 0
  148.     if(!Prog_Init()) return(0);
  149.  
  150.     //message structure
  151.     MSG msg;
  152.  
  153.     //message pump
  154.     for(;;)    
  155.     {
  156.         //look for a message
  157.         if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
  158.         {
  159.             //there is a message
  160.  
  161.             //check that we arent quitting
  162.             if(msg.message==WM_QUIT) break;
  163.             
  164.             //translate message
  165.             TranslateMessage(&msg);
  166.  
  167.             //dispatch message
  168.             DispatchMessage(&msg);
  169.         }
  170.  
  171.         //run main game loop
  172.         Prog_Loop();
  173.     }
  174.     
  175.     //clean up program data
  176.     Prog_Done();
  177.  
  178.     //return the wparam from the WM_QUIT message
  179.     return(msg.wParam);
  180. }
  181.  
  182. //////////////////////////////////////////////////////////////////////////////
  183. //INITIALIZATION
  184. //////////////////////////////////////////////////////////////////////////////
  185. bool Prog_Init()
  186. {
  187.     //resize the application window so that the client area is 512x384
  188.     //rectangle we will use for resizing
  189.     RECT rcClient;
  190.  
  191.     //set rectangle to desired dimensions
  192.     SetRect(&rcClient,0,0,512,384);
  193.  
  194.     //use adjust window rect to get the proper window rect
  195.     AdjustWindowRect(&rcClient,WS_BORDER | WS_SYSMENU | WS_VISIBLE,FALSE);
  196.  
  197.     //set window pos to change the width and height
  198.     SetWindowPos(hWndMain,NULL,0,0,rcClient.right-rcClient.left,rcClient.bottom-rcClient.top,SWP_NOMOVE);
  199.  
  200.     ////////////////////////////////////
  201.     //your initialization code goes here
  202.     ////////////////////////////////////
  203.  
  204.     return(true);//return success
  205. }
  206.  
  207. //////////////////////////////////////////////////////////////////////////////
  208. //CLEANUP
  209. //////////////////////////////////////////////////////////////////////////////
  210. void Prog_Done()
  211. {
  212.     //////////////////////////
  213.     //clean up code goes here
  214.     //////////////////////////
  215. }
  216.  
  217. //////////////////////////////////////////////////////////////////////////////
  218. //MAIN GAME LOOP
  219. //////////////////////////////////////////////////////////////////////////////
  220. void Prog_Loop()
  221. {
  222.     ///////////////////////////
  223.     //main game logic goes here
  224.     ///////////////////////////
  225. }
  226.  
  227.